package com.junwei.smsdemo.vo;

/**
 * @auther 王军伟
 * @create 2019-10-04 13:15
 * @desc
 */
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public Result() {
        this.code = R.SUCCESS.getCode();
        this.msg = R.SUCCESS.getMsg();
    }

    public Result(R r) {
        this.code = r.getCode();
        this.msg = r.getMsg();
    }

    public Result(R r, T data) {
        this(r);
        this.data = data;
    }

    public Result(String msg) {
        this.code = R.BAD_REQ.getCode();
        this.msg = msg;
    }

    public Result(String msg, T data) {
        this.code = R.BAD_REQ.getCode();
        this.msg = msg;
        this.data = data;
    }

    public static Result success() {
        return new Result(R.SUCCESS);
    }

    public static Result success(Object data) {
        return new Result(R.SUCCESS, data);
    }

    public static Result fail(R r) {
        return new Result(r);
    }

    public static Result fail() {
        return new Result(R.BAD_REQ);
    }

    public static Result fail(String msg) {
        return new Result(msg);
    }

    public static Result fail(Integer code, String msg) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Result)) {
            return false;
        } else {
            Result<?> other = (Result) o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

    @Override
    public String toString() {
        return "Result(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }
}
